package com.guoxin.part1.chapter2;

import java.util.concurrent.TimeUnit;

/**
 * 守护线程
 * 
 * @author guoxin
 * @date 2019/8/27
 */
public class DaemonThread {
	public static void main(String[] args) throws InterruptedException {
		// main 线程开始
		Thread thread = new Thread(() -> {
			try {
				while (true) {
					TimeUnit.SECONDS.sleep(1);
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		// 将thread设置为守护线程
		thread.setDaemon(true);
		// 启动thread线程
		thread.start();
		TimeUnit.SECONDS.sleep(2);

		System.out.println("Main thread finished lifecycle.");
	}
}
